#include <string.h>

typedef int Datatype;

#define MAX_SIZE 1024

struct Queue
{
    Datatype data[MAX_SIZE];
    int front, rear;
};

typedef struct Queue Queue;

void InitQueue(Queue *Q)
{
    Q->front = Q->rear = 0;
    memset(Q->data, 0, sizeof(Q->data));
}

int EmptyQueue(Queue *Q)
{
    return Q->front == Q->rear;
}

int FullQueue(Queue *Q)
{
    return ( Q->rear + 1 ) % MAX_SIZE == Q->front;
}

void EnQueue(Queue *Q, Datatype data)
{
    if ( FullQueue(Q) )
    {
        return;
    }

    Q->data[Q->rear] = data;

    Q->rear = (Q->rear + 1) % MAX_SIZE;
}

Datatype DeQueue(Queue *Q)
{
    Datatype data;
    if ( EmptyQueue(Q) )
    {
        return (-1);
    }
    
    data = Q->data[Q->front];
    Q->front = (Q->front + 1) % MAX_SIZE;

    return data;
}

